// import Vue from 'vue'
import store from './store'
import App from './App'
import util from './config/util'
import * as request from './config/api'
import uView from "uview-ui";
import { i18n, Vue } from '@/store/lang.js'
// 混入全局mixin
import mixin from './utils/mixin.js'
Vue.mixin(mixin);
Vue.use(uView);

/**
 * 乘法得到金额数据（保留精度问题）
 * 调用例子：var total = Number(parseInt(num)).mul(parseFloat(dj));
 * @param arg
 * @returns {String}
 */
Number.prototype.mul = function (arg)
{
    var m=0,s1=this.toString(),s2=arg.toString();
    try{m+=s1.split(".")[1].length}catch(e){}
    try{m+=s2.split(".")[1].length}catch(e){}
     
    var val = Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m);
    var m = val.toString();
	var num = m.split(".");
	if(num.length>1){
		var l = num[1];
		(l.length < 2) && (m+='0')
	}
	return m;
}

/**
 * 加法得到金额数据（保留精度问题）
 * 调用例子：var total = Number(0.09999999).add(0.09999999);
 * @param arg
 * @returns {String}
 */
Number.prototype.add = function(arg){   
    var r1,r2,m;   
    try{r1=this.toString().split(".")[1].length}catch(e){r1=0}   
    try{r2=arg.toString().split(".")[1].length}catch(e){r2=0}   
    m=Math.pow(10,Math.max(r1,r2))   
    
    var val = (this*m+arg*m)/m;
    var m = val.toString();
	var num = m.split(".");
	if(num.length>1){
		var l = num[1];
		(l.length < 2) && (m+='0')
	}
	return m;
}

/**
 * 减法得到金额数据（保留精度问题）
 * 调用例子：var total = Number(-0.09999999).sub(0.00000001);
 * @param arg
 * @returns {String}
 */
Number.prototype.sub = function (arg){   
    return this.add(-arg);
}

/**
 * 除法得到金额数据（保留精度问题）
 * 调用例子：var total = Number(0.000001).div(0.00000001);
 * @param arg
 * @returns {String}
 */
Number.prototype.div = function (arg){   
    var t1=0,t2=0,r1,r2;   
    try{t1=this.toString().split(".")[1].length}catch(e){};   
    try{t2=arg.toString().split(".")[1].length}catch(e){};   
    r1=Number(this.toString().replace(".",""))
    r2=Number(arg.toString().replace(".",""))   
    return (r1/r2)*Math.pow(10,t2-t1);   
}

Number.prototype.formatMoney = function (val){
    var m = val.toString();
	var num = m.split(".");
	if(num.length>1){
		var l = num[1];
		(l.length < 2) && (m+='0')
	}
	return m;
}

const msg = (title, duration=2000, mask=false, icon='none')=>{
	//统一提示方便全局修改
	if(Boolean(title) === false) return;
	uni.showToast({
		title,
		duration,
		mask,
		icon
	});
}

const prePage = ()=>{
	let pages = getCurrentPages();
	let prePage = pages[pages.length - 2];
	// #ifdef H5
	return prePage;
	// #endif
	return prePage.$vm;
}

Vue.config.productionTip = false
Vue.prototype.$fire = new Vue();
Vue.prototype.$store = store;
Vue.prototype.$api = {msg, prePage, util, request};

App.mpType = 'app'

const app = new Vue({
	i18n,  // 国际化
    ...App
})
app.$mount()
export default app